<?php

namespace app\api\controller;

use app\services\IdentifyService;
use Church\IDCard\IDCard;
use support\Db;
use support\Request;

class IdentifyController
{
    public function auth(Request $request)
    {
        try {
            $data = $request->post();

//            if (strlen($data['mobile']) != 11) {
//                throw new \Exception('不正确的手机格式');
//            }

            $idcard = new IDCard($data['idcard']);

            if (!$idcard->isValid()) {
                throw new \Exception('不正确的身份证格式');
            }

//            if (empty($data['front'])) {
//                throw new \Exception('身份证照片不能为空');
//            }
//
//            if (empty($data['back'])) {
//                throw new \Exception('身份证照片不能为空');
//            }

            IdentifyService::auth($data);

            return ok_rsp('成功');
        } catch (\Exception $e) {
            echo $e->getMessage() . $e->getTraceAsString();
            return err_rsp($e->getMessage());
        }
    }
}